/*
 * @lc app=leetcode.cn id=766 lang=cpp
 *
 * [766] 托普利茨矩阵
 */

// @lc code=start
class Solution
{
public:
  bool isToeplitzMatrix(vector<vector<int>>& matrix)
  {
    int m = matrix.size(), n = matrix[0].size();
    vector<int> row(n);
    for (int i = 0; i < n; ++i)
      row[i] = matrix[0][i];
    for (int i = 1; i < m; ++i) {
      for (int j = n - 1; j > 0; --j) {
        if (matrix[i][j] != row[j - 1])
          return false;
        row[j] = row[j - 1];
      }
      row[0] = matrix[i][0];
    }
    return true;
  }
};
// @lc code=end
